package com.example.gobang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManager {
    //用来表示用户在游戏大厅的状态
    private ConcurrentHashMap<Integer, WebSocketSession> gameHall = new ConcurrentHashMap<>();

    private ConcurrentHashMap<Integer, WebSocketSession> gameRoom = new ConcurrentHashMap<>();

    public void enterGame(Integer userId,WebSocketSession session) {
        gameHall.put(userId, session);
    }

    public void exitGame(Integer userId,WebSocketSession session) {
        gameHall.remove(userId, session);
    }

    public WebSocketSession getFromGameHall(Integer userId) {
        return gameHall.get(userId);
    }

    public void enterGameRoom(Integer userId,WebSocketSession session) {
        gameRoom.put(userId, session);
    }

    public void exitGameRoom(Integer userId,WebSocketSession session) {
        gameRoom.remove(userId, session);
    }

    public WebSocketSession getFromGameRoom(Integer userId) {
        return gameRoom.get(userId);
    }
}
